package ginsan.feignDemo.config;

public class test {
    static int num = 0;
    static volatile boolean flag = false;

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            for(;100>=num;){
                if(!flag&&((num==0)||++num%2==0)){
                    System.out.println("T1:"+num);
                    flag=true;
                }
            }
        });

        Thread t2 = new Thread(()->{
            for(;100>=num;){
                if(flag&&++num%2!=0){
                    System.out.println("T2:"+num);
                    flag=false;
                }
            }
        });

    t1.start();
    t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
